#include <assert.h>
#include <stdio.h>

char *my_strstr(const char*str1,const char*str2)
{
    assert(str1&&str2);
    if(*str2=='\0')
        return (char*)str1;
    const char*s1 = str1;
    const char*s2 = str2;
    const char*cp = str1;
    while (*cp)//until cp='\0'
    {
        s1 = cp;
        s2 = str2;
        while (*s1!='\0' && *s2!='\0' && *s1==*s2)
        {
            s1++;
            s2++;
        }
        if (*s2=='\0')//find
            return (char*)cp;
        cp++;//not find
    }
    return NULL;
}

void * memcpy(void*dst,const void*src,size_t count)
{
    void*ret = dst;
    assert(dst);
    assert(src);
    while (count--)
    {
        *(char*)dst = *(char*)src;
        dst = (char*)dst + 1 ;
        src = (char*)src + 1;
    }
    return (ret);
}

void * memmove(void*dst,const void*src,size_t count)
{
    void*ret = dst;

    if(dst<=src || (char*)dst>=((char*)src+count))
    {
        //低到高
        while (count--)
        {
            *(char*)dst = *(char*)src;
            dst = (char*)dst + 1 ;
            src = (char*)src + 1;
        }
    }
    else
    {
        //把指针放到高处
        dst = (char*)dst + count-1;
        src = (char*)src + count-1;
        //高到低
        while (count--)
        {
            *(char*)dst = *(char*)src;
            dst = (char*)dst - 1 ;
            src = (char*)src - 1;
        }
    }
}





















